package Q2;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static int n;
    public static int m;
    public static char[][] arr;
    public static Queue<int[]> queue = new LinkedList<>(); //存放出口坐标
    public static int exitNum; //可以到达的出口数量
    public static int minStep = Integer.MAX_VALUE; //最小步数
    public static int[] dx = {0, 0, 1, -1};
    public static int[] dy = {1, -1, 0, 0};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();
        m = scanner.nextInt();

        arr = new char[n][m];
        for (int i = 0; i < n; i++) {
            String str = scanner.next();
            for (int j = 0; j < m; j++) {
                arr[i][j] = str.charAt(j);
                if (arr[i][j] == 'e') {
                    //是出口
                    queue.offer(new int[]{i, j});
                }
            }
        }

        while (!queue.isEmpty()) {
            bfs(arr, queue.poll(), new boolean[n][m]);
        }

        if (exitNum == 0) {
            System.out.println(-1);
        } else {
            System.out.print(exitNum + " " + minStep);
        }
    }

    public static void bfs(char[][] arr, int[] arr1, boolean[][] flag) {
        int step = 0;

        Queue<int[]> queue1 = new LinkedList<>();
        queue1.offer(arr1);

        while (!queue1.isEmpty()) {
            int size = queue1.size();
            step++;
            while (size > 0) {
                size--;
                int[] arr2 = queue1.poll();
                int x = arr2[0];
                int y = arr2[1];
                flag[x][y] = true;
                for (int i = 0; i < 4; i++) {
                    int xx = x + dx[i];
                    int yy = y + dy[i];
                    if (xx >= 0 && xx < n && yy >= 0 && yy < m && !flag[xx][yy]) {
                        if (arr[xx][yy] == '.') {
                            queue1.offer(new int[]{xx, yy});
                            flag[xx][yy] = true;
                        } else if (arr[xx][yy] == 'k') {
//                            System.out.println((arr1[0] + 1) + ", " + (arr1[1] + 1));
                            exitNum++;
                            minStep = Math.min(minStep, step);
                            return;
                        }
                    }
                }
            }
        }
    }
}
